from django.db import models

# Create your models here.
class Temporal(models.Model):
    id = models.IntegerField()
    rfc = models.CharField(max_length=13, primary_key=True)
    metas = models.FloatField()
    factores = models.FloatField()
    latest_add = models.DateTimeField()
    file_name = models.CharField(max_length=50)
    estatus = models.IntegerField(default=1)
    hashid = models.CharField(max_length=32)
    nombre = models.CharField(max_length=100)
    class Meta:
        db_table='ztemporal'
        ordering =['latest_add']
        
    def get_latest_added(self):
        ultimo = Temporal.objects.latest('latest_add')
        
        relacionados = Temporal.objects.filter(latest_add=ultimo.latest_add)
class Repemp(models.Model):
    rfc = models.CharField(max_length=13, primary_key=True)
    nombre = models.CharField(max_length=100)
    clave_presupuestal = models.CharField(max_length=50)
    codigo = models.CharField(max_length=10)
    descr = models.CharField(max_length=100)
    ingreso_gob = models.DateField()
    ingreso_dep = models.DateField()
    cr = models.IntegerField()
    cr_descr = models.CharField(max_length=150)
    
    #Create Table repemp(
    #rfc varchar(13) not null primary key,
    #nombre varchar(100),
    #clave_presupuestal varchar(50),
    #codigo varchar(10),
    #descr varchar(100),
    #ingreso_gob date,
    #ingreso_dep date,
    #cr integer,
    #cr_descr varchar(150)
    def faltantes(self):
        u = Temporal.objects.latest('latest_add')
        t = Temporal.objects.filter(latest_add=u.latest_add)
        return t
    class Meta:
        db_table='repemp'
